﻿using System;
using System.Collections.Generic;
using System.Linq;
using Cinemachine;
using FlowCanvas;
using ImageEffects;
using LogSystem;
using NodeCanvas.Framework;
using UnityEngine;
using UnityEngine.Playables;
using Yoozoo.Gameplay.City;
using Yoozoo.Gameplay.Liberty.AI;
using Yoozoo.Gameplay.Liberty.Nodes;
using Yoozoo.Gameplay.Liberty.PlayerController;
using Yoozoo.Gameplay.Liberty.Pool;
using Yoozoo.Gta.Common;
using Random = UnityEngine.Random;

namespace Yoozoo.Gameplay.Liberty
{
    public enum GameCameraEnum
    {
        CityCamera = 1,
        WorldCamera = 2,
        PlayerCamera = 3,
    }
    
    public static class BlueprintUtils
    {
        public static HashSet<string> RecordList = new HashSet<string>();

        //public static MainControllerComponent MainControllerCom;

        public static Dictionary<string, BluePrintPoint> BlueprintPoints;
        public static List<BluePrintPoint> RandomBlueprintPoints;
        public static Dictionary<string, BlueprintCounter> BlueprintCounters;

        public static TimelineManager TimelineManager;

        public static LibertyManager LibertyManager;

        public static PlayerControlModeMgr PlayerController;

        public static PlayerEntity PlayerEntity;

        // 获得玩家摄像机
        public static Camera GetPlayerCamera()
        {
            return PlayerController.inputController.playerCamera;
        }

        public static Camera GetCamera(GameCameraEnum cameraEnum)
        {
            if (cameraEnum == GameCameraEnum.CityCamera)
            {
                if(CityManager.Instance != null)
                    return CityManager.Instance.mobileTouchCamera.Cam;
            }
            else if (cameraEnum == GameCameraEnum.WorldCamera)
            {
                if(WorldEntry.instance != null)
                    return WorldEntry.instance.GetCamera();
            }
            else if (cameraEnum == GameCameraEnum.PlayerCamera)
            {
                return GetPlayerCamera();
            }

            return null;
        }
        
        // 是否是玩家触发碰撞体
        public static bool IsPlayerTriggerCollider(Collider col)
        {
            return col == PlayerController.characterCtrl || col == PlayerController.playerCollider;
        }
        
        // 事件是否被记录
        public static bool HasBeenRecorded(string record)
        {
            return RecordList.Contains(record);
        }

        public static void ClearAllRecord()
        {
            RecordList.Clear();
        }

        // 获取蓝图点信息
        public static BluePrintPoint GetBlueprintPoint(string pointName)
        {
            if (BlueprintPoints != null)
            {
                BluePrintPoint point;
                if (BlueprintPoints.TryGetValue(pointName,out point))
                {
                    return point;
                }
            }
            
#if DEVELOPMENT_BUILD || UNITY_EDITOR
            Debug.LogError(LogModule.Blueprint,"获取蓝图点信息失败：" + pointName);
#endif
            
            return new BluePrintPoint();
        }

        public static BluePrintPoint GetRandomBlueprintPoint()
        {
            if (RandomBlueprintPoints != null)
            {
                var index = Random.Range(0, RandomBlueprintPoints.Count);
                var point = RandomBlueprintPoints[index];
                return point;
            }
#if DEVELOPMENT_BUILD || UNITY_EDITOR
            Debug.LogError(LogModule.Blueprint,"获取蓝图点信息失败：");
#endif
            
            return new BluePrintPoint();
        }

        // 改变相机Blend参数
        public static void ChangeCameraBlend(CinemachineBlendDefinition.Style style,float time)
        {
            PlayerController.cameraController.cameraBrain.m_DefaultBlend = new CinemachineBlendDefinition(style, time);
        }
        
        // 切换角色移动操作
        public static void SwitchMovementInput(bool allow)
        {
            PlayerController.SwitchMovementInput(allow);
        }
        public static void SwitchRootMotion(bool allow)
        {
            PlayerController.SwitchRootMotion(allow);
        }
        // 切换相机旋转操作
        public static void SwitchCameraInput(bool allow)
        {
            PlayerController.SwitchCameraInput(allow);
        }

        public static void OnlySwitchCameraInput(bool allow)
        {
            PlayerController.OnlySwitchCameraInput(allow);
        }

        public static void SwitchPlayerInputController(bool allow)
        {
            PlayerController.SwitchPlayerInputController(allow);
        }

        // 获取计数器，没有就新建一个
        public static BlueprintCounter TryGetBlueprintCounter(string name)
        {
            if (BlueprintCounters == null) {
                BlueprintCounters = new Dictionary<string, BlueprintCounter>();
            }

            if (BlueprintCounters.ContainsKey(name))
            {
                return BlueprintCounters[name];
            }

            var counter = new BlueprintCounter();
            BlueprintCounters[name] = counter;
            return counter;
        }

        // 设置角色自由瞄准
        public static void SetPlayerFreeAimOpen(bool isOpen)
        {
            PlayerController.playerLockTargetHelper.FreeAimOpen = isOpen;
        }

        // 设置角色战斗状态保持时长
        public static void SetPlayerKeepBattleDuration(float duration)
        {
            PlayerController.playerEntity.AIEntity.viewer.animationAgent.SetKeepBattleDuration(duration);
        }

        // 将角色移动到指定位置
        public static void PlayerTransmission(Vector3 pos,Vector3 rot)
        {
            PlayerController.PlayerTransmission(pos,rot);
        }

        // 角色自动导航到目的地
        public static void SetPlayerDestination(Vector3 destination, NavType navType = NavType.None)
        {
            PlayerController.SetPlayerDestination(destination, navType);
        }
        
        // 判断进入碰撞的是否是玩家
        public static bool IsMainPlayer(Collider collider)
        {
            if (collider &&
                collider.transform.CompareTag("Player"))
            {
                return true;
            }
            return false;
        }
        
        // 播放Timeline
        public static void PlayTimeline(string name, 
            Action<PlayableDirector> onStopped,
            Action<PlayableDirector> onStart, 
            Action onPreStart,
            DirectorWrapMode wrapMode = DirectorWrapMode.None, 
            string path = "", string cameraType = "", float planeDistance = 0, Transform parent = null,ETimelinePathType pathType = ETimelinePathType.City)
        {
            if (TimelineManager == null)
            {
                TimelineManager = new TimelineManager();
            }
            
            TimelineManager.PlayTimeline(name,onStopped, onStart, onPreStart,null, 
                wrapMode, path, cameraType, planeDistance, parent,pathType);
        }

        // 停止Timeline
        public static void StopTimeline(string name)
        {
            if (TimelineManager == null)
            {
                TimelineManager = new TimelineManager();
            }
            TimelineManager.StopTimeline(name);
        }

        public static void Pause()
        {
            TimelineManager?.Pause();
        }

        public static void Resume()
        {
            TimelineManager?.Resume();
        }

        // 播放特效
        public static void PlayEffect(int configId, int uniqueId,Vector3 pos,Vector3 angle)
        {
            Transform effect = LibertyPoolMgr.GetInstance("LibertyPoolMgr").GetEffectObject(configId, uniqueId);
            if (effect!=null)
            {
                effect.gameObject.SetActive(true);
                effect.position = pos;
                effect.eulerAngles = angle;
            }
        }
        
        // 销毁特效
        public static void DestroyEffect(int uniqueId)
        {
            LibertyPoolMgr.GetInstance("LibertyPoolMgr")?.RecycleEffect(uniqueId);
        }

        // 添加一个Npc
        public static void AddNpc(string npcName, int uniqueId, Vector3 pos, Quaternion rot)
        {
            LibertyManager.NpcManager.AddNpc(npcName,uniqueId,pos,rot);
        }
        
        // 移除一个Npc
        public static void RemoveNpc(int uniqueId)
        {
            LibertyManager.NpcManager.RemoveNpc(uniqueId);
        }

        public const int PLAYER_NPC_ID = -1;

        public static GameObject GetNpc(int uniqueId)
        {
            if (uniqueId == PLAYER_NPC_ID)
            {
                return PlayerController.playerModel.gameObject;
            }
            return LibertyManager.NpcManager.GetNpc(uniqueId);
        }

        public static Rigidbody GetPlayerNpcRigidBody()
        {

            return PlayerController.rigidBody;
        }


        public static void OperateLookAtCamera(Vector3 position, Vector3 eulerAngles,float fov)
        {
            PlayerController.cameraController.Switch2LookAtCamera(position,eulerAngles,fov);
            PlayerController.cameraController.SetCameraLookAtTransform(null);
        }
        
        public static void OperatePlayerInputCamera(float localAngleH, float localAngleV)
        {
            //PlayerController.inputCamera.SetAngle(localAngleH,localAngleV);
        }

        public static void Switch2LookAtCamera(Vector3 position, Vector3 eulerAngles, 
            Vector3 lookAtPos, Transform lookAt = null,float fov = 0)
        {
            PlayerController.cameraController.Switch2LookAtCamera(position,eulerAngles,fov);
            if (lookAt == null) {
                PlayerController.cameraController.SetCameraLookAtTransform(lookAt);
            }
            else {
                PlayerController.cameraController.SetCameraLookAtPos(lookAtPos);
            }
        }

        public static void ResetInputCamera()
        {
            LibertyAIUtils.PlayerController.inputCamera.ResetCamera();
        }
        
        public static void Switch2InputCamera()
        {
            PlayerController.cameraController.Switch2InputCamera();
        }

        public static void Switch2HangingCamera()
        {
            PlayerController.cameraController.Switch2HangingCamera();
        }

        public static void Switch2BehaviorCamera(string cameraName, Action<BehaviorCamera> callBack = null)
        {
            PlayerController.cameraController.Switch2BehaviorCamera(cameraName,callBack);
        }

        public static LightController GetLightController(string mark)
        {
            LightController.lightControllerMap.TryGetValue(mark, out LightController lightController);
            return lightController;
        }

        #region Lua层

        public static void SetIsInGuide(bool isInGuide)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.setIsInGuide").Action(isInGuide);
        }

        public static bool IsInMainUI()
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isInMainUI").Func<int, bool>(0);
        }

        public static bool HasRadarItem(int eventId)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasRadarItem").Func<int, bool>(eventId);
        }

        public static bool AutoReqClaimBuildingReward(int buildingId, int buildingIndex, int targetLv)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.AutoReqClaimBuildingReward").Func<int,int,int,bool>(buildingId, buildingIndex,targetLv);
        }

        public static bool CallLuaFuncSwitch(string funcName, string argString)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.callLuaFuncSwitch").Func<string, string, bool>(funcName, argString);
        }

        public static int GetTroopHeroCount(int troopIndex)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.getTroopHeroCount").Func<int, int>(troopIndex);
        }

        public static bool IsUiShowing(string pageName)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isUiShowing").Func<string, bool>(pageName);
        }

        public static bool IsGuideConditionMatch(string condition, int state)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isGuideConditionMatch")
                .Func<string, int, bool>(condition, state);
        }

        public static bool IsInScene(string sceneName)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isInScene").Func<string, bool>(sceneName);
        }
        
        // 发送事件记录
        public static void SendRecordRequest(string record)
        {
            if (RecordList.Contains(record))
            {
                //Debug.LogWarning(LogModule.Blueprint,"重复记录：" + record);
                return;
            }
            ResidentHandler.Inst.GetFunction("CityLuaFunction.sendRecordRequest").Action(record);
            RecordList.Add(record);
        }

        public static void SendGuideRequest(int groupId, int guideId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.sendGuideRequest").Action(groupId, guideId);
        }

        // 打开或关闭UI界面
        public static void OpenCloseUI(bool isOpen,string panelName = null,string param1 = null,string param2 = null,string param3 = null,Action action = null)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.bpOpenCloseUI").Action(isOpen,panelName,param1,param2,param3,action);
        }

        // UI界面是否显示
        public static bool UIIsShowing(string pageName)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.uiIsShowing").Func<string,bool>(pageName);
        }

        // 展示对话界面
        public static void ShowDialoguePanel(int id, int childId, FlowNode parentNode, bool autoClose, float autoCloseTime)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showDialoguePanel").Action(id, childId, parentNode, autoClose, autoCloseTime);
        }

        public static void ShowMovieBlackEffect(bool isOpen, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showMovieBlackEffect").Action(isOpen, onStopped);
        }
        
        // 解开空气墙
        public static void UnlockAirWall(string wallName)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.unLockAirWall").Action(wallName);
        }
        
        // 封锁
        public static void LockAirWall(string wallName)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.lockAirWall").Action(wallName);
        }
        
        // 添加功能性空气墙 
        public static void AddFeatureAirWall(string wallName, Vector3 pos, Quaternion rot, Vector3 scale)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.addFeatureAirWall").Action(wallName,pos,rot,scale);
        }

        // 切换内城的场景
        public static void SwitchCityScene(EnterCityScene.CitySceneType sceneType,Action callback)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchCityScene").Action((int)sceneType,callback);
        }
        
        public static void Switch2HangingScene(Action callBack,string mark)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switch2HangingScene").Action(callBack, mark);
        }
        
        public static void SetHangingPreTimeLine(string bluePrintName)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.SetHangingPreTimeLine").Action(bluePrintName);
        }
        
        // 触发新手引导组
        public static void TriggerGuideGroup(int groupId, int guideId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.triggerGuideGroup").Action(groupId,guideId);
        }
        
        // 触发新手引导功能
        public static void TriggerGuideAction(int actionType, string actionParams)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.triggerGuideAction").Action(actionType,actionParams);
        }
        
        public static void AddGuideTag(string tagName)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.addGuideTag").Action(tagName);
        }
        
        // 通知场景新手引导准备完毕
        public static void GuideReady2Finish()
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.guideReady2Finish").Call();
        }
        
        public static void BeginRpgEventBattle(int levelId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.beginRpgEventBattle").Action(levelId);
        }

        public static void BeginSurvivorBattle(int missionId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.beginSurvivorBattle").Action(missionId);
        }
        
        public static void ShowBattleStart()
        {
            ResidentHandler.Inst.GetFunction("L_RpgManager.ShowBattleStartFromGuide").Action(0);
        }

        public static bool CheckCanDeckGuideClick(int heroId)
        {
            return (bool)ResidentHandler.Inst.GetFunction("L_RpgManager.CheckCanDeckGuideClick").Call(heroId)[0];
        }
        
        public static void BeginDeckGuideClick(int heroId)
        {
            ResidentHandler.Inst.GetFunction("L_RpgManager.BeginDeckGuideClick").Action(heroId);
        }

        public static void DeckGuideClickSuccess(int heroId)
        {
            ResidentHandler.Inst.GetFunction("L_RpgManager.DeckGuideClickSuccess").Action(heroId);
        }
        
        public static bool CheckCanDeckGuideDrag(int heroId)
        {
            return (bool)ResidentHandler.Inst.GetFunction("L_RpgManager.CheckCanDeckGuideDrag").Call(heroId)[0];
        }
        
        public static void BeginDeckGuideDrag(int heroId)
        {
            ResidentHandler.Inst.GetFunction("L_RpgManager.BeginDeckGuideDrag").Action(0);
        }

        public static void DeckGuideDragSuccess(int heroId)
        {
            ResidentHandler.Inst.GetFunction("L_RpgManager.DeckGuideDragSuccess").Action(heroId);
        }

        
        // 是否通过Rpg关卡
        public static bool HasPassRpgLevel(int levelId)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasPassRpgLevel").Func<int,bool>(levelId);
        }

        // 是否通过了某引导步骤
        public static bool HasPassGuideEvent(int guideEventId)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasPassGuideEvent").Func<int,bool>(guideEventId);
        }

        public static bool HasFinishCityEvent(int eventId)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasFinishCityEvent").Func<int,bool>(eventId);
        }

        public static bool HasBuilding(int buildingId, int level, int num)
        {
            var args = string.Format("{0},{1},{2}", buildingId, level, num);
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasBuilding").Func<string,bool>(args);
        }

        public static bool HasResource(int type, int id, int num)
        {
            var args = string.Format("{0},{1},{2}", type, id, num);
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasResource").Func<string,bool>(args);
        }

        public static bool HasCityEvent(int eventId)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasCityEvent").Func<int,bool>(eventId);
        }

        public static bool HasPrettyGirls()
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasPrettyGirls").Func<int,bool>(1);
        }

        public static bool HasEmployee(int buildingId, int employeeId, int level, int num)
        {
            var args = string.Format("{0},{1},{2},{3}", buildingId, employeeId, level, num);
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.hasEmployee").Func<string,bool>(args);
        }
        
        public static bool IsCityBusinessStateMatch(int state)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isCityBusinessStateMatch").Func<int,bool>(state);
        }
        
        public static bool IsIndustryCanBuild(int indID)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isIndustryCanBuild").Func<int, bool>(indID);
        }

        public static bool IsCityTaskGroupNow(int groupID)
        {
            return ResidentHandler.Inst.GetFunction("CityLuaFunction.isCityTaskGroupNow").Func<int, bool>(groupID);
        }

        public static void AddCityTaskCount(int taskId)
		{
            ResidentHandler.Inst.GetFunction("CityLuaFunction.addCityTaskCount").Action(taskId);
        }

        public static void GetCityTask(int taskId)
		{
            ResidentHandler.Inst.GetFunction("CityLuaFunction.getCityTask").Action(taskId);
        }
        
        //设置主相机渲染
        public static void SwitchSceneCamera(bool state)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchSceneCamera").Action(state);
        }

        public static void SwitchThirdPersonController(bool enable)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchThirdPersonController").Action(enable);
        }
        
        public static void PlayVideo(string name, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.playVideo").Action(name, onStopped);
        }

        public static void PlayCommanderShow(string heroId, Action<PlayableDirector> onFirstFrame,
            Action<PlayableDirector> onFinish)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.playCommanderShow").Action(heroId, onFirstFrame, onFinish);
        }

        public static void ShowStreetOccupyEffect(int streetId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showStreetOccupyEffect").Action(streetId);
        }

        public static void TriggerGoto(int gotoId, bool keepInGuide,
            Action<PlayableDirector> onStopped, Action<PlayableDirector> onException)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.triggerGoto").Action(gotoId, keepInGuide, onStopped, onException);
        }

        public static void InterruptGoto(int gotoId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.interruptGoto").Action(gotoId);
        }

        public static void ClientReport(int eventId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.clientReport").Action(eventId);
        }

        public static void PlayEnterCityCamera(Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.playEnterCityCamera").Action(onStopped);
        }

        public static void PlayDeblockAnim(int deblockId, string title, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.playDeblockAnim").Action(deblockId, title, onStopped);
        }
        
        public static void SecondConfirmDeblock(int deblockId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.secondConfirmDeblock").Action(deblockId);
        }
        
        public static void PlayPowerUpAnim(int fromValue, int toValue, Action<PlayableDirector> onComplete)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.PlayPowerUpAnim").Action(fromValue, toValue, onComplete);
        }
        
        public static void PlayChapterAnim(int chapterId, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.playChapterAnim").Action(chapterId, onStopped);
        }

        public static void ShowWebImage(int webId, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showWebImage").Action(webId, onStopped);
        }
        
        public static void ShowGetNewHero(List<int> heroes, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.ShowGetNewHero").Action(heroes, onStopped);
        }

        public static void SwitchSandboxLod(int lod, int percent, float time, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.SwitchSandboxLod").Action(lod, percent, time, onStopped);
        }

        public static void MoveSandboxPos(string key, float time, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.MoveSandboxPos").Action(key, time, onStopped);
        }

        public static void UpdateLoadingProgress(int progress, string msg)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.updateLoadingProgress").Action(progress, msg);
        }

        public static void SwitchCityNpcDisplay(bool enable)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchCityNpcDisplay").Action(enable);
        }
        
        // 开关某种类型的Hud显示
        public static void SwitchHudDisplay(CityHudEnum hudEnum, bool active)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchHudDisplay").Action((int)hudEnum,active);
        }
        // 开关某种类型的Hud显示
        public static void SwitchAllHudDisplay(bool active)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchAllHudDisplay").Action(active);
        }

        // 重置到场景
        public static void ResetScene(string sceneName, Action callback)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.resetScene").Action(sceneName,callback);
        }

        public static void Switch2Scene(string sceneName, string sceneParams, Action callback)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switch2Scene").Action(sceneName,sceneParams,callback);
        }

        public static void DispatchNews(int newsId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.reqCityNewsAdd").Action(newsId);
        }

        public static void DispatchLuaEvent(int eventId, int argInt, string argString, bool argBool)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.dispatchEvent").Action(eventId, argInt, argString, argBool);
        }

        public static void ShowMainUi(Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showMainUi").Action(onStopped);
        }

        public static void SwitchEventEntity(int eventId, bool active)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchEventEntity").Action(eventId, active);
        }
        
        public static void SetPlayerChessPieceVisible(bool isVisible)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.setPlayerChessPieceVisible").Action(isVisible);
        }
        
        public static void SetCityRoofVisible(bool isVisible)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showOrHideRoof").Action(isVisible);
        }
        
        public static void RequestBuildingLvUp(int buildingId, int buildingIndex, string type)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.requestBuildingLvUp").Action(buildingId, buildingIndex, type);
        }
        
        public static void RequestCompleteAreaEvent(int eventId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.requestCompleteAreaEvent").Action(eventId);
        }
        
        public static void CacheCityCameraPos()
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.cacheCityCameraPos").Action();
        }
        
        public static void RecoverCacheCityCameraPos()
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.recoverCacheCityCameraPos").Action();
        }

        public static void FocusCityEvent(int eventId, float x, float y, float z, float time, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.focusCityEvent").Action(eventId, x, y, z, time, onStopped);
        }
        
        public static void FocusCityBuilding(int buildingId, float x, float y, float z, float time, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.focusCityBuilding").Action(buildingId, x, y, z, time, onStopped);
        }

        public static void FocusCityPos(float x, float y, float z, float time, Action<PlayableDirector> onStopped)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.focusCityPos").Action(x, y, z, time, onStopped);
        }

        public static void ChangeCityEvent(int eventId, bool showHud, bool showEffect)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.changeCityEvent").Action(eventId, showHud, showEffect);
        }

        public static void SwitchCityFog(bool active)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchCityFog").Action(active);
        }
        
        public static void SwitchCityCamera(bool active)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchCityCamera").Action(active);
        }

        public static void SwitchCityTouchInput(bool active, bool keepInGuide = false)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchTouchInput").Action(active, keepInGuide, true);
        }

        public static void AddEventCache(string sceneName, string eventName, bool isVTask=false)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.addEventCache").Action(sceneName, eventName, isVTask);
        }

        public static void ClearEventCache(string sceneName, string eventName, bool isVTask=false)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.clearEventCache").Action(sceneName, eventName, isVTask);
        }

        public static void SetForewordTask(bool state, int taskId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.setForewordTask").Action(state, taskId);
        }
        
        public static void StreetEventCountDown(float time)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.streetEventCountDown").Action(time);
        }

        public static void StreetEventCountDownPause()
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.pauseEventCountDown").Action();
        }
        
        public static void StreetEventCountDownResume()
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.resumeEventCountDown").Action();
        }
        
        
        public static void ExeEventFunc(string funcName)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.ExeEventFunc").Action(funcName);
            
            
        }
        public static void UpdateStreetEventTips(string langKey)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.updateStreetEventTips").Action(langKey);
        }
        
        public static void LoadBpStreetEventComplete(int streetEventId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.loadBpStreetEventComplete").Action(streetEventId);
        }
        
        public static void OpenStreetInteractivePanel(int actionId,string langKey,string iconPath)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.openStreetInteractivePanel").Action(actionId, langKey, iconPath);
        }
        
        public static void CloseStreetInteractivePanel()
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.closeStreetInteractivePanel").Action();
        }

        public static void SwitchExitVehicleOperation(bool enable)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchExitVehicleOperation").Action(enable);
        }
        
        public static void ClearLuaFunction()
        {
            var handler = ResidentHandler.Inst;
            if(handler == null) return;
            handler.RemoveFunction("CityLuaFunction.showDialoguePanel");
            handler.RemoveFunction("CityLuaFunction.unLockAirWall");
            handler.RemoveFunction("CityLuaFunction.lockAirWall");
            handler.RemoveFunction("CityLuaFunction.addFeatureAirWall");
            handler.RemoveFunction("CityLuaFunction.switchCityScene");
            handler.RemoveFunction("CityLuaFunction.triggerGuideGroup");
            handler.RemoveFunction("CityLuaFunction.triggerGuideAction");
            handler.RemoveFunction("CityLuaFunction.guideReady2Finish");
            handler.RemoveFunction("CityLuaFunction.beginRpgEventBattle");
            handler.RemoveFunction("CityLuaFunction.hasPassRpgLevel");
            handler.RemoveFunction("CityLuaFunction.hasPassGuideEvent");
            handler.RemoveFunction("CityLuaFunction.isIndustryCanBuild");
            handler.RemoveFunction("CityLuaFunction.isCityTaskGroupNow");
            handler.RemoveFunction("CityLuaFunction.addCityTaskCount");
            handler.RemoveFunction("CityLuaFunction.getCityTask");
            handler.RemoveFunction("CityLuaFunction.switchSceneCamera");
            handler.RemoveFunction("CityLuaFunction.switchThirdPersonController");
            handler.RemoveFunction("CityLuaFunction.playVideo");
            handler.RemoveFunction("CityLuaFunction.triggerGoto");
            handler.RemoveFunction("CityLuaFunction.clientReport");
            handler.RemoveFunction("CityLuaFunction.playEnterCityCamera");
            handler.RemoveFunction("CityLuaFunction.playDeblockAnim");
            handler.RemoveFunction("CityLuaFunction.playChapterAnim");
            handler.RemoveFunction("CityLuaFunction.showWebImage");
            handler.RemoveFunction("CityLuaFunction.ShowGetNewHero");
            handler.RemoveFunction("CityLuaFunction.updateLoadingProgress");
            handler.RemoveFunction("CityLuaFunction.SwitchSandboxLod");
            handler.RemoveFunction("CityLuaFunction.MoveSandboxPos");
            handler.RemoveFunction("CityLuaFunction.showMainUi");
            handler.RemoveFunction("CityLuaFunction.focusCityEvent");
            handler.RemoveFunction("CityLuaFunction.focusCityPos");
            handler.RemoveFunction("CityLuaFunction.streetEventCountDown");
            handler.RemoveFunction("CityLuaFunction.updateStreetEventTips");
            handler.RemoveFunction("CityLuaFunction.loadBpStreetEventComplete");
            handler.RemoveFunction("CityLuaFunction.closeStreetInteractivePanel");
            handler.RemoveFunction("CityLuaFunction.switchExitVehicleOperation");
        }

        public static void ClearAllLuaFunctions()
        {
            var handler = ResidentHandler.Inst;
            if(handler == null) return;
            handler.Clear();
        }

        #endregion

        public static void TimeLineJumpToTime(string tname , double toTime)
		{
            if (TimelineManager == null)
            {
                TimelineManager = new TimelineManager();
            }
            TimelineManager.JumpToTime(tname, toTime);
        }

        public static void SendGraphEvent(string eventName, FlowNode sender)
		{
            Graph.SendGlobalEvent(eventName, null, sender);
        }

        public static void WriteTimelineResultEvent(string eventName)
        {
            if (TimelineManager == null)
            {
                TimelineManager = new TimelineManager();
            }
            TimelineManager.UpdateQTETimelineResultName(eventName);
        }

        public static void CreateCityObject(string name, string aniName, Vector3 position, Vector3 rotation,int id)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.createCityObject").Action(name, aniName, position, rotation,id);
        }

        public static void RemoveCityObject(string name, int id)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.removeCityObject").Action(name, id);
        }

        public static void ShowCityEventHud(int eventId)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.showCityEventHud").Action(eventId);
        }

        public static void SwitchCityBuildingLvUpShowingState(int buildingId, int buildingIndex, bool active)
        {
            ResidentHandler.Inst.GetFunction("CityLuaFunction.switchCityBuildingLvUpShowingState").Action(buildingId, buildingIndex, active);
        }
    }
}